#include<bits/stdc++.h>
using namespace std;
int t,a[200005],maxn=0;
bool b[200005];
void dfs(int k,int n)
{
	if(k>n)
	{
		int sum=0;
		for(int i=1;i<=n;i++)
		{
			int w=i-1;
			while(b[i]!=b[w]&&w>=1)
			    w--;
			if(w==0) continue;
			if(a[w]==a[i]) sum+=a[i];
		}
		maxn=max(maxn,sum);
		return;
    }
    b[k]=true;
    dfs(k+1,n);
    b[k]=false;
    dfs(k+1,n);
}
int main()
{
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        for(int i=1;i<=n;i++)
            cin>>a[i];
        b[1]=true;
        dfs(2,n);
        b[1]=false;
        dfs(2,n);
        cout<<maxn<<endl;
        maxn=0;
    }
    
    return 0;
}
